package com.xiaojianone.controller;

import com.xiaojianone.pojo.Headline;
import com.xiaojianone.service.HeadlineService;
import com.xiaojianone.utils.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName  HeadLineController
 * Author  XiaojianOne
 * Date  2025/2/18 22:22
 * Version  8.0
 */

@RestController
@RequestMapping("headline")
@CrossOrigin
public class HeadLineController {

    @Autowired
    private HeadlineService headlineService;

    @PostMapping("publish")
    public Result publish(@RequestBody Headline headline,@RequestHeader String token){

        Result result = headlineService.publish(headline,token);

        return result;
    }


    @PostMapping("findHeadlineByHid")
    public Result findHeadlineByHid(@Param("hid") Integer hid){

        Headline headline = headlineService.getById(hid);

        Map data = new HashMap();
        data.put("headline",headline);
        return Result.ok(null);
    }


    @PostMapping("update")
    public Result update(@RequestBody Headline headline){

        Result result = headlineService.updateDate(headline);

        return result;
    }


    @PostMapping("removeByHid")
    public Result removeByHid(Integer hid){

        headlineService.removeById(hid);

        return Result.ok(null);
    }
}
